<!DOCTYPE html>
<html lang="en">
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
</head>
<body  class="hold-transition">
    <div id="app">
        <div class="content-header">
            <h1>会员管理<small>会员档案</small></h1>
            <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>会员管理</el-breadcrumb-item>
                <el-breadcrumb-item>会员档案</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="app-container">
            <div class="box">
                <div class="filter-container">
                    <el-input placeholder="姓名/电话/档案号" v-model="pagination.queryString" style="width: 200px;" class="filter-item"></el-input>
                    <el-button @click="findPage(1)" class="dalfBut">查询</el-button>
                    <el-button type="primary" class="butT" @click="findAll">查询全部</el-button>
                    <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                </div>
                <el-table border size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                    <el-table-column type="index" align="center" label="序号"></el-table-column>
                    <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
                    <el-table-column prop="name" sortable label="姓名" align="center"></el-table-column>
                    <el-table-column label="性别" align="center">
                        <template slot-scope="scope">
                            <span>{{ scope.row.sex == '0' ? '不限' : scope.row.sex == '1' ? '男' : '女'}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="idCard"  label="卡号" align="center"></el-table-column>
                    <el-table-column prop="email" label="邮箱" align="center"></el-table-column>
                    <el-table-column prop="regTime" sortable label="注册时间" align="center"></el-table-column>
                    <el-table-column prop="birthday" sortable label="生日" align="center"></el-table-column>
                    <el-table-column prop="remark" label="备注" align="center"></el-table-column>
                    <el-table-column fixed="right" label="操作" align="center">
                        <template slot-scope="scope">
                            <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                            <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="pagination-container">
                    <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            @size-change="handleSizeChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            :page-sizes="[1,2,5,10]"
                            layout="sizes,total, prev, pager, next, jumper"
                            :total="pagination.total">
                    </el-pagination>
                </div>

                <!-- 编辑标签弹层 -->
                <div class="add-form">
                    <el-dialog title="编辑会员档案" :visible.sync="dialogFormVisible4Edit">
                        <el-form ref="dataEditForm" :model="formData"  label-position="right" label-width="100px">
                            <el-row>
                                <el-col :span="18">
                                    <el-form-item label="档案码" prop="fileNumber">
                                        <el-input v-model="formData.fileNumber"/>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="18">
                                    <el-form-item label="姓名" prop="name">
                                        <el-input v-model="formData.name"/>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="18">
                                    <el-form-item label="性别">
                                        <el-select v-model="formData.sex">
                                            <el-option label="男" value="1"></el-option>
                                            <el-option label="女" value="2"></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="18">
                                    <el-form-item label="邮箱">
                                        <el-input v-model="formData.email"/>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="18">
                                    <el-form-item disabled label="注册日期" prop="regTime">
                                        <el-input v-model="formData.regTime"/>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="18">
                                    <el-form-item label="生日" prop="birthday">
                                        <el-input v-model="formData.birthday"/>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="18">
                                    <el-form-item label="卡号" prop="idCard">
                                        <el-input v-model="formData.idCard"/>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="18">
                                    <el-form-item label="手机号" prop="phoneNumber">
                                        <el-input v-model="formData.phoneNumber"/>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="36">
                                    <el-form-item label="备注">
                                        <el-input v-model="formData.remark" type="textarea"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </el-form>
                        <div slot="footer" class="dialog-footer">
                            <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                            <el-button type="primary" @click="handleEdit()">确定</el-button>
                        </div>
                    </el-dialog>
                </div>

            </div>
        </div>
    </div>
</body>
<script>
    new Vue({
        el:'#app',
        data:{
            pagination:{
                currentPage: 1,//当前页码
                pageSize:5,//每页显示的记录数
                total:0,//总记录数
                queryString:null//查询条件
            },
            dataList: [],//当前页要展示的分页列表数据
            dialogFormVisible4Edit:false,//编辑页的隐藏参数
            formData: {},
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            //初始化完成后调用分页方法
            this.findPage();
        },

        methods:{
            findPage(page){
                if(page==1){
                    this.pagination.currentPage=1;
                }
                var param= {
                    currentPage: this.pagination.currentPage,
                    pagesize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                }
                axios.post("/member/findPage.do",param).then((resp)=>{
                    this.dataList=resp.data.rows;
                    this.pagination.total=resp.data.total;
                })
            },
            findAll(){
                this.pagination.currentPage=1;
                this.pagination.pageSize=5;
                this.pagination.queryString='';
                this.findPage();
            },
            handleCurrentChange(currentPage){
                this.pagination.currentPage=currentPage;
                this.findPage();
            },
            handleSizeChange(pageSize){
                this.pagination.pageSize=pageSize;
                this.findPage();
            },
            //根据id查询数据库中这一行的值，再赋值
            handleUpdate(row){
                console.log(row);
                //显示编辑框
                axios.get("/member/findMemById/"+row.id+".do").then((resp)=>{
                   if(resp.data.flag){
                       this.formData=resp.data.data;
                       this.dialogFormVisible4Edit=true;
                   }else{
                       this.$message.error(resp.data.message);
                   }
                });
                // this.formData=row;
            },
            handleEdit(){
                console.log(this.formData);
                axios.post("/member/edit.do",this.formData).then((resp)=>{
                    if(resp.data.flag){
                        this.$message({
                            type:'success',
                            message:resp.data.message
                        })
                        //隐藏修改窗口
                        this.dialogFormVisible4Edit=false;
                        this.findPage();
                    }else{
                        this.$message.error(resp.data.message);
                        return false;
                    }
                });
            }


        }
    })
</script>
</html>